// 2020-11-06
exports.formatTime = (date) => {
  if (date != null) {
    let formatDate = new Date(date)
    return translateTime(formatDate)
  } else {
    return ''
  }
}

// 2020-11-06 00:00
exports.formatDateTime = (date) => {
  if (date != null) {
    let formatDateTime = new Date(date)
    let hours = formatDateTime.getHours()
    let minutes = formatDateTime.getMinutes()
    // let seconds = formatDateTime.getSeconds()
    let time = translateTime(formatDateTime)
    if (hours < 10) {
      time += ' 0' + hours + ':'
    } else {
      time += ' ' + hours + ':'
    }
    if (minutes < 10) {
      time += '0' + minutes
    } else {
      time += minutes
    }
    return time
  } else {
    return ''
  }
}

// 00:00
exports.formatTimeStr = (date) => {
  if (date != null) {
    let formatDateTime = new Date(date)
    let hours = formatDateTime.getHours()
    let minutes = formatDateTime.getMinutes()
    let time = ''
    if (hours < 10) {
      time += '0' + hours + ':'
    } else {
      time += hours + ':'
    }
    if (minutes < 10) {
      time += '0' + minutes
    } else {
      time += minutes
    }
    return time
  } else {
    return ''
  }
}

// 2020-11-05T16:00:00.000+0000
function translateTime (formatDate) {
  let year = formatDate.getFullYear()
  let month = formatDate.getMonth() + 1
  let day = formatDate.getDate()
  let time = year + '-'
  if (month < 10) {
    time += '0' + month + '-'
  } else {
    time += month + '-'
  }
  if (day < 10) {
    time += '0' + day
  } else {
    time += day
  }
  return time
}
